local function SpawnMonsters(inst)
    local monster_names = {"bird_mutant","bird_mutant_spitter","mushgnome","slurper","mosquito",
                        "nightmarebeak","crawlingnightmare","worm","hound",
                        "firehound","icehound","mutatedhound","spider","spider_warrior","spider_hider","spider_spitter",
                    "spider_dropper","spider_moon","moonpig","spat","wasphive","knight","bishop","rook","knight_nightmare",
                        "bishop_nightmare","rook_nightmare","walrus","tallbird"}
    local ret_name = inst.npc_base_lib:GetRandom(monster_names)
    local num = math.random(3,6)
    local points = inst.npc_base_lib:GetSurroundPoints({
        target = inst,
        num = num,
        range = 7
    })
    for k, pt in pairs(points) do
        local monster = SpawnPrefab(ret_name)
        monster.Transform:SetPosition(pt.x, 0, pt.z)
        monster:AddTag("npc_task")
        SpawnPrefab("npc_fx_collapse"):PushEvent("Set",{
            pt = pt,
            -- sound_off = true
            type = "small",
        })
        if monster.components.combat then
            monster.components.combat:SetTarget(monster:GetNearestPlayer(true))
        end
    end
end

local function SpawnBoss(inst)
    local boss_name = {"bearger","deerclops","dragonfly","beequeen","leif_sparse","leif","deciduoustree","spiderqueen",
                         "warg","shadow_rook"}
    local num = math.random(2,5)
    local ret_name = inst.npc_base_lib:GetRandom(boss_name)
    if boss_name ~= "shadow_rook" then
        ------------ 如果不是三基佬
        local points = inst.npc_base_lib:GetSurroundPoints({
            target = inst,
            num = num,
            range = 8
        })
        for k, pt in pairs(points) do
            local monster = SpawnPrefab(ret_name)
            monster.Transform:SetPosition(pt.x, 0, pt.z)
            monster:AddTag("npc_task")
            if ret_name == "deciduoustree" and monster.StartMonster then
                monster:StartMonster(true)
            end
            -- SpawnPrefab("collapse_small").Transform:SetPosition(pt.x,0,pt.z)
            SpawnPrefab("npc_fx_collapse"):PushEvent("Set",{
                pt = pt,
                -- sound_off = true
            })
            if monster.components.combat then
                monster.components.combat:SetTarget(monster:GetNearestPlayer(true))
            end
        end
        -------------------------------------------------------------------------------
    else    --------- 三基佬

        local points = inst.npc_base_lib:GetSurroundPoints({
            target = inst,
            num = 3,
            range = 8
        })
        local tempNames = {
            [1] = "shadow_knight",
            [2] = "shadow_bishop",
            [3] = "shadow_rook"
        }
        for i, pt in pairs(points) do
            local monster = SpawnPrefab(tempNames[i])
            monster.Transform:SetPosition(pt.x, 0, pt.z)
            monster:AddTag("npc_task")
            SpawnPrefab("collapse_small").Transform:SetPosition(pt.x,0,pt.z)
            if monster.components.combat then
                monster.components.combat:SetTarget(monster:GetNearestPlayer(true))
            end
        end

    end
end

local function start_event(inst,player)
    if math.random(100) <= 10 then
        SpawnBoss(player)
    else
        SpawnMonsters(player)
    end
    inst:Remove()
end
local function fx()
    local inst = CreateEntity()
    inst.entity:AddTransform()

    inst:AddTag("INLIMBO")
    inst:AddTag("FX")

    if not TheWorld.ismastersim then
        return inst
    end

    inst:ListenForEvent("Set",function(inst,player)
        start_event(inst,player)
    end)

    return inst
end

return Prefab("npc_card_monsters",fx)